package cn.xzqwjw.taskmanager.common.converter;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * 自定义序列化LocalDateTime
 *
 * @author rush
 */
public class CustomLocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {

  @Override
  public void serialize(LocalDateTime value, JsonGenerator generator, SerializerProvider serializers)
      throws IOException {
    generator.writeNumber(value.toInstant(ZoneOffset.of("+8")).toEpochMilli());
  }

}
